package BufferReader;

public class BufferReader {
	byte[] buffer = null;
	int pos = 0;
	
	public BufferReader(byte[] bs) {
		buffer = bs;
	}
	
	public void Seek(int offset) {
		pos = offset;
	}
	
	public void Skip(int offset) {
		pos += offset;
	}
	
	public void Reset() {
		pos = 0;
	}
	
	public byte ReadByte() {
		return buffer[pos++];
	}
	
	public char ReadChar() {
        char c = (char)((buffer[pos++] << 8)
        				+ (buffer[pos++] & 0xFF));
        return c;
    }
	
	public int ReadInt() {
        int i = (buffer[pos++] << 24)
				 + ((buffer[pos++] & 0xFF) << 16)
				 + ((buffer[pos++] & 0xFF) << 8)
				 + (buffer[pos++] & 0xFF);
        return i;
	}
	
	public String ReadString(){
		pos += 2; //skip string length
		int length = buffer.length - pos;
		String s = null;
		try{
			s = new String(buffer, pos, length, "UTF-8");
		}
		catch(Exception e){
			e.printStackTrace();
		}
		pos = buffer.length;
		return s;
	}
}
